﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public static class RectTransformExtensions
    {
        private static Vector3[] pos = new Vector3[4];
       
        public static Vector3 GetWorldCenter(this RectTransform transform)
        {
            transform.GetWorldCorners(pos);
            return (pos[0] + RectTransformExtensions.pos[2]) *  0.5f;
        }

        public static float GetWorldCenterX(this RectTransform transform)
        {
            transform.GetWorldCorners(pos);
            return (pos[0].x + RectTransformExtensions.pos[2].x) * 0.5f;
        }
        public static float GetWorldCenterY(this RectTransform transform)
        {
            transform.GetWorldCorners(pos);
            return (pos[0].y + RectTransformExtensions.pos[2].y) * 0.5f;
        }
        public static float GetWorldCenterZ(this RectTransform transform)
        {
            transform.GetWorldCorners(pos);
            return (pos[0].z + RectTransformExtensions.pos[2].z) * 0.5f;
        }


    }
}

